alExpired($dismissedAt) { $dismissedTimestamp = strtotime($dismissedAt); if ($dismissedTimestamp === false) { return true; } $daysElapsed = (current_time('timestamp') - $dismissedTimestamp) / self::SECONDS_IN_A_DAY; return $daysElapsed >= self::TEMP_DISMISS_DAYS; } private function getAllNoticeDefinitions() { $notices = []; $segment = $this->detectUserReviewSegment(); if ($segment !== '') { $reviewKey = "review_notice_{$segment}"; $notices[$reviewKey] = [ 'type' => 'temp', 'callback' => function () use ($reviewKey, $segment) { return $this->getReviewHtml($reviewKey, $segment); }, 'condition' => true, ]; } $notices['upgrade_to_pro'] = [ 'type' => 'temp', 'callback' => [$this, 'getUpgradeNoticeHtml'], 'condition' => $this->shouldShowUpgradeNotice(), ]; return apply_filters('ninja_tables_admin_notices', array_merge($notices, self::$customNotices)); } private function detectUserReviewSegment() { global $wpdb; $tables = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery "SELECT ID, post_date FROM {$wpdb->posts} WHERE post_type = 'ninja-table' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 10" ); $installTime = strtotime(get_option('ninja_tables_installed_at')); $daysSinceInstall = (current_time('timestamp') - $installTime) / self::SECONDS_IN_A_DAY; if (empty($tables)) { return $daysSinceInstall >= 7 ? 'no_tables' : ''; } if ($daysSinceInstall < 7) { return ''; } $usedDragDrop = $usedAdvanced = $createdWithin10Days = false; foreach ($tables as $table) { $provider = ninja_table_get_data_provider($table->ID); if ($provider === 'drag_and_drop') { $usedDragDrop = true; } else { $usedAdvanced = true; } if ((current_time('timestamp') - strtotime($table->post_date)) <= (self::SECONDS_IN_A_DAY * 10)) { $createdWithin10Days = true; } } if ($usedDragDrop && !$usedAdvanced) { return 'only_drag'; } if ($usedAdvanced && !$usedDragDrop) { return 'only_advanced'; } if ($usedDragDrop && $usedAdvanced && count($tables) >= 2 && $createdWithin10Days) { return 'both_modes_recent'; } return ''; } private function shouldShowUpgradeNotice() { return defined('NINJAPROPLUGIN_VERSION') && version_compare(NINJAPROPLUGIN_VERSION, '5.0.0', '<'); } private function renderNoticeTemplate($key, $message, $showRateButton = false) { $key = esc_attr($key); $rateButton = ''; if ($showRateButton) { $reviewUrl = esc_url('https://wordpress.org/support/plugin/ninja-tables/reviews/'); $rateNow = __('Rate Now', 'ninja-tables'); $rateButton = "{$rateNow}
"; } return '
' . $message . '
'; } private function getUpgradeNoticeHtml($key) { $url = esc_url(admin_url('plugins.php?s=ninja-tables-pro&plugin_status=all')); $message = '

' . esc_html__('Update Ninja Tables Pro Plugin', 'ninja-tables') . '

' . sprintf( /* translators: %1$s: opening link tag, %2$s: closing link tag */ __('You are using an outdated version. Some features may not work properly. %1$sPlease update to the latest version%2$s', 'ninja-tables'), "", '' ) . '

'; return $this->renderNoticeTemplate($key, $message); } private function getReviewHtml($key, $segment) { $messages = $this->getReviewMessages(); $message = isset($messages[$segment]) ? $messages[$segment] : ''; if (empty($message)) { return ''; } return $this->renderNoticeTemplate($key, $message, $segment === 'both_modes_recent'); } private function getReviewMessages() { // Link markup is passed in rather than embedded, so a translation cannot break a URL. $docsLink = ""; $videosLink = ""; $advancedLink = ""; $simpleLink = ""; return [ 'no_tables' => sprintf( /* translators: %1$s/%2$s: link tags around "documentation", %3$s/%4$s: link tags around "tutorial videos" */ __('Having trouble creating your first table? Check out Ninja Tables %1$sdocumentation%2$s or watch %3$stutorial videos%4$s to get you started.', 'ninja-tables'), $docsLink, '', $videosLink, '' ), 'only_drag' => sprintf( /* translators: %1$s: opening link tag, %2$s: closing link tag */ __('Looks like you\'re having fun with Drag & Drop!
Did you know Ninja Tables has a lot more fun features in the Advanced Table mode? See the %1$sdocumentation%2$s and try it!', 'ninja-tables'), $advancedLink, '' ), 'only_advanced' => sprintf( /* translators: %1$s: opening link tag, %2$s: closing link tag */ __('Looks like you\'re having fun using Advanced mode for your tables.
Did you know Ninja Tables makes things even easier in Drag and Drop mode? See the %1$sdocumentation%2$s and try it!', 'ninja-tables'), $simpleLink, '' ), 'both_modes_recent' => sprintf( /* translators: %s: five star icons */ __('You\'re doing amazing!
Loving Ninja Tables? Leave us a %s review. It will encourage us to come up with more and more features.
', 'ninja-tables'), $this->getStarsSvg() ) ]; } private function getStarsSvg() { $svg = ''; return str_repeat($svg, 5); } public function appendNotices() { $notices = $this->notices(); if (empty($notices)) { return; } wp_localize_script('ninja-tables', 'ninjaTablesAdminNotices', [ 'notices' => $notices, 'ajax_url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('ninja_tables_admin_notice_nonce'), ]); } }